﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASPNETVN.PORTAL.Components.UI;
using ASPNETVN.PORTAL.Components.Configuration.Settings;
using ASPNETVN.PORTAL.Components.UI.DataTypes;
using ASPNETVN.PORTAL.Components.Security;
using ASPNETVN.PORTAL.Components.Helpers;
using LMHTX.Modules.DIRECTORY.TEAM;
using System.Collections;
using ASPNETVN.PORTAL.Components.Share;
using System.Data;

namespace LMHTX.Modules.DIRECTORY.TEAM.MENU
{
    public partial class Main : PortalModuleControl
    {
        public Main()
        {
            ModuleSettingItem itemSetting = new ModuleSettingItem(new StringDataType());
            itemSetting.Value = Guid.Empty.ToString();
            itemSetting.Name = "ModuleID của Module DIRECTORY.TEAM";
            itemSetting.Description = "ModuleID của Module DIRECTORY.TEAM";
            itemSetting.SortOrder = 1;
            this.BaseSettings.Add("DIRECTORY.TEAM.ModuleID", itemSetting);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            Hashtable settings = this.Settings;
            Guid moduleID = new Guid(settings["DIRECTORY.TEAM.ModuleID"].ToString());

            // Left Pane.
            string url = string.Empty;
            LiteralControl literal = new LiteralControl("");
            literal.Text += "<div class='MenuLink'>";

            url = ResolveClientUrl(HttpUrlBuilder.BuildModulePageUrl(moduleID, 0, ModulePages.TeamList));
            literal.Text += string.Format("<a class='MenuLinkItem' href='{0}'>» Xem tất cả</a>", url);

            literal.Text += "</div>";
            // Manager Permission.
            if (PortalSecurity.HasManageAuthorization(moduleID))
            {
                literal.Text += "<div class='MenuLinkGroup'>Quản trị</div>";
                literal.Text += "<div class='MenuLink'>";

                url = HttpUrlBuilder.BuildAddEditUrl(moduleID, 0, "AreaManager");
                url = url.Substring(2);
                literal.Text += string.Format("<a class='MenuLinkItem' href='{0}'>» Địa bàn</a>", url);

                url = HttpUrlBuilder.BuildAddEditUrl(moduleID, 0, "TypeManager");
                url = url.Substring(2);
                literal.Text += string.Format("<a class='MenuLinkItem' href='{0}'>» Loại hình</a>", url);

                url = HttpUrlBuilder.BuildAddEditUrl(moduleID, 0, "CareerManager");
                url = url.Substring(2);
                literal.Text += string.Format("<a class='MenuLinkItem' href='{0}'>» Ngành nghề</a>", url);

                url = HttpUrlBuilder.BuildAddEditUrl(moduleID, 0, "TrainingManager");
                url = url.Substring(2);
                literal.Text += string.Format("<a class='MenuLinkItem' href='{0}'>» Hình thức đào tạo</a>", url);

                url = HttpUrlBuilder.BuildAddEditUrl(moduleID, 0, "AddEditItem");
                url = url.Substring(2);
                literal.Text += string.Format("<a class='MenuLinkItem' href='{0}'>» Tạo mới tổ hợp tác</a>", url);
                               
                // Type.
                url = HttpUrlBuilder.BuildAddEditUrl(moduleID, 0, "TEAMManager");
                url = url.Substring(2);
                literal.Text += string.Format("<a class='MenuLinkItem' href='{0}'>» Danh sách tổ hợp tác</a>", url);
                
                literal.Text += "</div>";
            }
            try
            {
                //Loai hinh
                List<Components.Type> types = new List<Components.Type>();
                types = Components.Type.SelectCollectionAll(moduleID);
                if (types.Count > 0)
                {
                    url = HttpUrlBuilder.BuildModulePageUrl(moduleID, 0, ModulePages.TeamList, "typeid={0}", 0);
                    url = url.Substring(2);
                    literal.Text += string.Format("<div class='MenuLinkGroup'><a href='{0}'>{1}</a></div>", url, "Loại hình");
                    literal.Text += "<div class='MenuLink'>";

                    foreach (Components.Type type in types)
                    {
                        url = HttpUrlBuilder.BuildModulePageUrl(moduleID, 0, ModulePages.TeamList, "typeid={0}", type.ID);
                        url = url.Substring(2);

                        literal.Text += string.Format("<a class='MenuLinkItem' href='{0}'>» {1}</a>", url, type.Title);
                    }
                    literal.Text += "</div>";
                }

                //Nganh nghe
                List<Components.Career> careers = new List<Components.Career>();
                careers = Components.Career.SelectCollectionAll(moduleID);
                if (careers.Count > 0)
                {
                    url = HttpUrlBuilder.BuildModulePageUrl(moduleID, 0, ModulePages.TeamList, "careerid={0}", 0);
                    url = url.Substring(2);
                    literal.Text += string.Format("<div class='MenuLinkGroup'><a href='{0}'>{1}</a></div>", url, "Ngành nghề");
                    literal.Text += "<div class='MenuLink'>";

                    foreach (Components.Career career in careers)
                    {
                        url = HttpUrlBuilder.BuildModulePageUrl(moduleID, 0, ModulePages.TeamList, "careerid={0}", career.ID);
                        url = url.Substring(2);

                        literal.Text += string.Format("<a class='MenuLinkItem' href='{0}'>» {1}</a>", url, career.Title);
                    }
                    literal.Text += "</div>";
                }
                //Địa bàn
                List<Components.Area> areas = new List<Components.Area>();
                areas = Components.Area.SelectCollectionAll(moduleID);
                if (areas.Count > 0)
                {
                    url = HttpUrlBuilder.BuildModulePageUrl(moduleID, 0, ModulePages.TeamList, "areaid={0}", 0);
                    url = url.Substring(2);
                    literal.Text += string.Format("<div class='MenuLinkGroup'><a href='{0}'>{1}</a></div>", url, "Địa bàn");
                    literal.Text += "<div class='MenuLink'>";

                    foreach (Components.Area area in areas)
                    {
                        url = HttpUrlBuilder.BuildModulePageUrl(moduleID, 0, ModulePages.TeamList, "areaid={0}", area.ID);
                        url = url.Substring(2);

                        literal.Text += string.Format("<a class='MenuLinkItem' href='{0}'>» {1}</a>", url, area.Title);
                    }
                    literal.Text += "</div>";
                }
            }
            catch { }
            
            literal.Text += "</div>";
            ContentPane.Controls.Add(literal);
        }
    }
}